/* 汉诺塔 */

#include<iostream>
#include<list>
#include<cstdlib>
#include<algorithm>
#include<thread>
using namespace std;

constexpr int N = 6;
list<int> listHanoi[3];

void Step(char src, char dest)
{
	int idxSrc = src - 'A';
	int idxDest = dest - 'A';

	int v = listHanoi[idxSrc].back();
	listHanoi[idxSrc].pop_back();
	listHanoi[idxDest].push_back(v);

	system("clear");
	for (int i = 0; i < 3; i++)
	{
		cout<< (char)('A' + i) << ": ";
		for_each(listHanoi[i].begin(), listHanoi[i].end(), [](int e) -> void {cout<< e << " ";});
		cout<< "\n";
	}
	this_thread::sleep_for(500ms);
}

void Hanoi(int n, char src, char mid, char dest)
{
	if (n == 1)
	{
		Step(src, dest);
	}
	else
	{
		Hanoi(n - 1, src, dest, mid);
		Step(src, dest);
		Hanoi(n - 1, mid, src, dest);
	}
}

int main(void)
{
	for (int i = N; i > 0; i--)
	{
		listHanoi[0].push_back(i);
	}

	Hanoi(N, 'A', 'B', 'C');
}

